<?php
class PasswordReminderForm extends BaseForm{
   public function configure()
   {

     $this->setNameFormat();

     $this->widgetSchema['email'] = new sfWidgetFormInput(array(), array('title' => 'E-mail'));
     
     $this->setValidators( array(
        'email' => new sfValidatorCallback(array('callback' => array($this, 'validateEmail')), array()),
      ));

	 $this->setDefault('email', 'E-mail');


   }

   public function getUser(){
	   return Doctrine::getTable('PublicUser')->findOneByEmail($this->getValue('email'));
   }

   public function validateEmail($validator, $email){
	   if(($user = Doctrine::getTable('PublicUser')->findOneByEmail($email))){
		   return $email;
	   }else{
		   throw new sfValidatorError($validator, 'no user with email: ' . $email);
	   }


   }
   
   public function setNameFormat(){
   		$this->widgetSchema->setNameFormat('reminder[%s]');
   }
}